# Contributor: Chloe Kudryavtsev <code@toast.bunkerlabs.net>
# Maintainer: Mike Crute <mike@crute.us>
pkgname=rclone
pkgver=1.66.0
pkgrel=1
pkgdesc="Rsync for cloud storage"
url="https://rclone.org/"
# s390x: https://github.com/cronokirby/saferith/pull/51
arch="all !s390x"
license="MIT"
makedepends="go"
checkdepends="fuse"
subpackages="$pkgname-doc $pkgname-bash-completion $pkgname-fish-completion $pkgname-zsh-completion"
source="rclone-$pkgver.tar.gz::https://github.com/rclone/rclone/archive/refs/tags/v$pkgver.tar.gz"
options="!check net" # tests fail in CI due filesystem access

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build

	./rclone genautocomplete bash rclone.bash
	./rclone genautocomplete fish rclone.fish
	./rclone genautocomplete zsh rclone.zsh
}

check() {
	# backend/{ftp,sftp,swift,webdav,seafile}: uses docker(1) for tests
	# backend/{local,memory}: fails in docker envs, but not on real machines
	# fs/rc: fails on ppc64le
	# shellcheck disable=SC2046
	go test $(go list ./... | grep -v \
		-e 'backend/ftp$' \
		-e 'backend/local$' \
		-e 'backend/memory$' \
		-e 'backend/sftp$' \
		-e 'backend/swift$' \
		-e 'backend/webdav$' \
		-e 'backend/seafile$' \
		-e 'fs/rc$'
		)
}

package() {
	install -Dm755 "$builddir"/rclone \
		"$pkgdir"/usr/bin/rclone

	mkdir -p "$pkgdir"/sbin
	ln -sfv ../usr/bin/rclone "$pkgdir"/sbin/mount.rclone
	ln -sfv rclone "$pkgdir"/usr/bin/rclonefs

	install -Dm644 "$builddir"/rclone.1 \
		"$pkgdir"/usr/share/man/man1/rclone.1

	install -Dm644 "$builddir"/rclone.bash \
		"$pkgdir"/usr/share/bash-completion/completions/rclone

	install -Dm644 "$builddir"/rclone.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/rclone.fish

	install -Dm644 "$builddir"/rclone.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_rclone
}

sha512sums="
955ed1457ebe7e6ac2288484109ba263601e147f767ce71b70e14ddcf3f97659d90704de094e4e83c0820267e0f41b1950fc3db534bb3577bcf27f0a2401eb84  rclone-1.66.0.tar.gz
"
